package com.zfx.mapper;

import com.zfx.pojo.Admin;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.common.Mapper;

import javax.persistence.Column;
import java.sql.Date;
import java.util.List;

/**
 * @description:
 * @author: zfx
 * @version: 1.0
 * @time: 2020-05-07 22:30
 * <p>
 * 修改历史：
 * 修改日期      修改人员    版本    内容
 * 2020-05-07   zfx       1.0
 */
//@Repository
public interface IAdminMapper extends Mapper<Admin> {

    //自己写的查询要自己重新封装哦
    @Select("select * from tbs_admin where login_id=#{loginId} and password=#{password}")
    @Results(id="adminInfo", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "login_id", property = "loginId"),
            @Result(column = "user_name", property = "userName"),
            @Result(column = "password", property = "password"),
            @Result(column = "phone", property = "phone"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_date", property = "updateDate"),
            @Result(column = "permission", property = "permission"),

    })
    public Admin login(Admin admin);

    @Select("<script>select * from tbs_admin where 1=1 " +
            "<if test='loginId != null'> and login_id = #{loginId}</if> " +
            "<if test='userName != null'> and user_name like #{userName}</if> " +
            "<if test='phone != null'> and phone like #{phone}</if></script>")
    @Results(id="adminList", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "login_id", property = "loginId"),
            @Result(column = "user_name", property = "userName"),
            @Result(column = "password", property = "password"),
            @Result(column = "phone", property = "phone"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_date", property = "updateDate"),
            @Result(column = "permission", property = "permission"),

    })
    public List<Admin> findByAdmin(Admin admin);

    @Select("<script>select count(*) from tbs_admin where 1=1 " +
            "<if test='loginId != null'> and login_id = #{loginId}</if> " +
            "<if test='userName != null'> and user_name like #{userName}</if> " +
            "<if test='phone != null'> and phone like #{phone}</if></script>")
    public int countByAdmin(Admin admin);
}
